home *** CD-ROM | disk | FTP | other *** search
/ Java Interactive Reference Guide / Java Interactive Reference Guide.iso / autorun / java_d.dir / 00178_15.txt < prev    next >
Encoding:
Text File  |  1980-01-11  |  1.8 KB  |  58 lines

  1. /*
  2.  * File: p02.java
  3.  *
  4.  * Description:  This example program will take any incoming string
  5.  *       and display it.  The point of this example is to present
  6.  *       how Java uses basic input/output functionality.
  7.  *
  8.  * Modifications:  11/1/95 CValcarcel Created.
  9.  *
  10.  * NO WARRANTY, EXPRESSED OR IMPLIED, BLAH, BLAH, BLAH.
  11.  *
  12.  * THIS IS EXAMPLE CODE AND SHOULD NOT BE USED FOR  
  13.     ANYTHING
  14.  * EXCEPT INSTRUCTIONAL PURPOSES.
  15.  *
  16.  */
  17.  
  18. //
  19. // Let's change the name of our class as it will now be
  20. // more generic.  Same rule applies about the implied
  21. // "extends" ("extends Object" is implied).
  22. //
  23. class EchoString {
  24.     public static void main( String args[] )
  25.     {
  26.         //
  27.         // If only one arg comes in we want to print it without
  28.         // a trailing blank so we print this solitary arg
  29.         // if one actually exists.  This is a bit of overkill,
  30.         // but examples shouldn't be too far off the mark.
  31.         //
  32.         if ( args.length > 0 )
  33.             System.out.print( args[0] );
  34.  
  35.         //
  36.         // I only need i in my for loop so I declare it
  37.         // within the parens (similar to C++).  args is
  38.         // an array so, by definition, its internal variable,           
  39.         // length, contains its length (which equates to
  40.         // the number of arguments.  No more argc!).
  41.         //
  42.         for ( int i = 1; i < args.length; i++ )
  43.         {
  44.             System.out.print( " " );   // Separate the arguments
  45.             System.out.print( args[i] );
  46.         }
  47.  
  48.         //
  49.         // We do this because System.out will only flush on a newline
  50.         // (don't believe me?  Look in Java/src/java/io/PrintStream.java.
  51.         // the PrintStream autoflush variable is set to false
  52.         // when the first constructor calls the second with an
  53.         // autoflush argument of false).
  54.         //
  55.         System.out.println();
  56.     }
  57. }
  58.